#!/bin/#!/usr/bin/env bash

if [ ! -x $1 ]; then
    chmod +x $1
fi

if [ ! -d $2 ]; then
    mkdir $3
    cd $3 && git clone $4
else
    cd $2 && git pull
    cd $2 && git log --pretty=format:'%h -%d %s (%cr) <%an>' --abbrev-commit -1
    # console 日志 git log 没换号
    # echo -n
    echo -e '\r'
fi

cd $2 && mvn clean install compile -Dmaven.test.skip=true

cp_path=$(find "$2/target/" -name "*.jar")
name=$(cd "$2/target/" && ls | grep "jar$")
cp $cp_path $5

# 杀掉进程
pid=$(ps -ef | grep $name | grep '/bin/java' | grep -v grep | awk '{print $2}')
for i in $pid
do
  echo "the process [ $i ] is running to sand kill "
  kill $i
  echo "killed process [ $i ]"
done

#cd $5 && nohup java -jar $name &
#nohup java -jar $5$name &